﻿using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
//using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text.RegularExpressions;
//using System.Xml.Linq;
using Jungle.Code.DAL;
using Jungle.Code.BLL;
using Jungle.Code.Core;
using Jungle.Code.Utils;


using Jungle.Prodamo.AdvertManager;
using Jungle.Prodamo.Core;

public partial class User : BaseUserModule
{
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
    }

    protected override void Render(HtmlTextWriter writer)
    {
        Advert adv = new Advert();
        adv.GetAllPremiums();
        String body;

        if (adv.AdvertList.Count != 0)
        {

            Random rnd = new Random();

            writer.Write("<table width=100% cellspacing=0 cellpadding=2 border=0 align=center>\n");
            writer.Write("<tr>\n");

            for (int i = 0; i < 4; i++)
            {
                writer.Write("<td height=100% width=20%>\n");

                Advert va1 = adv.AdvertList[rnd.Next(0, adv.AdvertList.Count)];
                if (va1.Body.Length > 20) body = va1.Body.Substring(0, 20) + "...";
                else body = va1.Body + "...";

                writer.Write("<table cellspacing=0 cellpadding=4 border=0 width=100% height=100% class='text1'>\n");
                writer.Write("<tr>\n");

                writer.Write("<td rowspan=2 align=center valign=middle>\n");

                writer.Write("<a href='" + UrlHelper.GetSiteUrl() + "/ru/adverts.aspx?cmd=Show&Id=" + va1.AdvertId.ToString() + "'>");
                writer.Write("<img src='" + UrlHelper.GetSiteUrl() + va1.ImageUrl.Substring(1));

                writer.Write("'width=70 height=70 border=0/></a>\n");


                writer.Write("</td>\n");

                writer.Write("</tr>\n");

                writer.Write("<tr>\n");


                writer.Write("<td style=text-align:center;>\n");

                writer.Write("<a class=main_link href=" + UrlHelper.GetSiteUrl() + "/ru/adverts.aspx?cmd=Show&Id=" + va1.AdvertId.ToString() + ">" + va1.Title + "<h5>" + body + "</h5> <br> " + "</a>\n");

                //writer.Write("<a class=main_link href=" + UrlHelper.GetSiteUrl() + "/ru/adverts.aspx?cmd=Show&Id=" + va1.AdvertId.ToString() + ">" + body + "</a>\n");

                writer.Write("</td>\n");
                writer.Write("</tr>\n");

                writer.Write("</tr>\n");
                writer.Write("</table>\n");
                writer.Write("</td>\n");

            }

            writer.Write("</tr>\n");
            writer.Write("</table>\n");


        }
        base.Render(writer);
    }

}
